package com.service.sys.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.entity.sys.Message;
import com.mapper.sys.MessageMapper;
import com.service.sys.MessageService;
import com.service.sys.UserVoService;
import com.vo.sys.MessageVo;
import com.vo.sys.UserVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements MessageService {

    @Resource
    private UserVoService userVoService;
    @Resource
    private MessageMapper messageMapper;

    @Override
    public List<MessageVo> getHistoryMsg(String fromId, String toId) {
        List<Message> messageList = messageMapper.getHistoryMsg(fromId, toId);
        List<MessageVo> messageVoList = new ArrayList<>();
        for (Message message : messageList) {
            MessageVo messageVo = new MessageVo();
            messageVo.setMessage(message);
            UserVo fromUserVo = userVoService.getById(message.getFromUser());
            messageVo.setFromUser(fromUserVo);
            messageVo.setToUser(userVoService.getById(message.getToUser()));
            messageVoList.add(messageVo);
        }
        return messageVoList;
    }
}
